// const { EEventType } = require("XrFrame");

// pages/try/upload/upload.js
const app = getApp();

Page({
  /**
   * 页面的初始数据
   */
  data: {
    imgs: [],
    socketOpen: false,
    src: '',
    canvasStyle: {},
    xiangxi: '',

 
    opacity: false, // 显示图标
    opacityimg: true, //隐藏封面

    yingcang: true,

    shangjiaxinaa: '', //商家信息
    yingcangaa: true,


    SHANGHU_CODE:'',
    SHANGHU_NAME:"",
    value:'',


    openid: '',
    jiami: '',
    OPEN_ID: '',
    session_key: '',




    jindu: '',
    dizhi: '',
    SHANGHU_ID:'',
    weidu: '',

    page: 1, // 起始页码
    totalPage: Number, //最大页码数

  },


  // reset() {
  //   this.setData({
  //     SHANGHU_NAME: '', //商家名称
  //   })
  // },


  chakanyihuoqu(){
    wx.navigateTo({
      url: '../../pages/xianshangjiadingweitongji/xianshangjiadingweitongji',

    })
  },


  guanbi(){
    this.setData({

      yingcang: true,
      yingcangaa: true
    })
  },




  shanghu(e) {
    console.log(e);
    console.log(e.currentTarget.dataset.item.SHANGHU_NAME);
    console.log(e.currentTarget.dataset.item.SHANGHU_ID);

    this.setData({
      SHANGHU_ID:e.currentTarget.dataset.item.SHANGHU_ID,
      SHANGHU_NAME:e.currentTarget.dataset.item.SHANGHU_NAME,
      yingcang: true,
      value:'',

    })
  },



  onSearch(event) {

    // const n = event.detail

    // this.setData({
    // n:event.detail

    // })

    // console.log(n);
    this.getvidelist()
  },


  onchange(event) {
    console.log(event);
    const value = event.detail
    console.log(value);
    this.setData({
      value:value
    })
  },

  getvidelist(n = '') {
    var that = this
    wx.request({
      url: app.globalData.interface+'/squareDance/API_5251_VisitingShanghuList',
      method: 'POST',
      data: {

        EMPLOYEE_ID: that.data.mealsList,
        OPEN_ID: that.data.openid, //用户OPEN_ID
        session_key: that.data.session_key,
        OPEN_UUID: that.data.jiami,
        currentPage: '',
        KeyWord: that.data.value,
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        console.log('res', res.data.data);

        if (res.data.data == '') {
          wx.showModal({
            title: '暂无信息',
            content: '请重新搜索',
          });

          this.setData({
            yingcang: true,
            value:'',
          })
        } else {

          that.setData({
            shangjiaxin: res.data.data,
            yingcang: false
          })
          console.log(111);
        }
      },
     
    })
  },



  
  weihuoqushang() {

    var that = this


    wx.request({
      url: app.globalData.interface+'/squareDance/API_5253_unGetAddShanghuList',
      method: 'POST',
      data: {

        EMPLOYEE_ID: that.data.mealsList,
        OPEN_ID: that.data.openid, //用户OPEN_ID
        session_key: that.data.session_key,
        OPEN_UUID: that.data.jiami,
        currentPage: '',
        KeyWord: '',
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        console.log('res', res.data.data);
        console.log('res', res);

        console.log('翻页', res.data.data[0].page.totalPage);


        wx.hideLoading()
        if (res.data.result == 'success' && res.data.data.length != 0) {
          console.log('翻页', res.data.data[0].page.totalPage);

          const copypage = JSON.stringify(res.data.data[0].page.totalPage)
          const totalPage = JSON.parse(copypage)
          console.log('totalPage', totalPage);


          that.setData({
            shangjiaxinaa: res.data.data,
            yingcangaa: false,
            totalPage: totalPage
          })
          console.log(111);

          console.log('最大页码数', this.data.totalPage);

        } else {
          wx.showModal({
            title: '温馨提示',
            content: '暂无信息',
          });
        }

      },
      fail: (res => {
        wx.hideLoading()
      })
    })
  },






  back() {
    wx.navigateBack({
      delta: 1,
    })
  },







  submit() {

    var that = this



    console.log('111', that.data.jindu);



    if (that.data.jindu == '' && that.data.weidu == '') {


      wx.showModal({
        title: '温馨提示',
        content: '请点击获取位置信息',
        success: function (res) {
          if (res.confirm) { //这里是点击了确定以后
            console.log('用户点击确定')

          } else { //这里是点击了取消以后
            console.log('用户点击取消')
          }
        }
      })


    } else if (that.data.SHANGHU_NAME!='') {
      console.log('555', that.data.DANCE_NAME);
      wx.showLoading({
        title: '加载中...',
      })

      wx.request({
        url: app.globalData.interface+'/squareDance/API_5253_saveShanghuAdd',
        method: 'POST',
        data: {
          SHANGHU_ID: that.data.SHANGHU_ID,
          LONGITUDE: that.data.jindu,
          DIMENSION: that.data.weidu,
          EMPLOYEE_ID: that.data.mealsList,
        

        },
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: res => {
          console.log('res', res);
          console.log('res', res.data.result);

          if (res.data.result == 'success') {
            wx.hideLoading()
            const text = res.data.data
            wx.showModal({
              content: text,
              showCancel: false,
            });

          } else {
            wx.showModal({
              content: res.data.data,
              showCancel: false,
            });
            wx.hideLoading()
          }
        },
        fail: (res => {
          wx.hideLoading()
        })
      })

    } else {
      wx.showModal({
        content: '请完善信息',
        showCancel: false,
      });
    }


  },

  huoqudingwwi() {

    let that = this


    wx.getLocation({
      type: 'wgs84',
      success(res) {
        console.log(res)
        const latitude = res.latitude
        const longitude = res.longitude
        const speed = res.speed
        const accuracy = res.accuracy
        console.log(latitude);
        console.log(longitude);
        console.log(speed);
        console.log(accuracy);

        if (res.latitude != '') {
              
          wx.showModal({
            title: '温馨提示',
            content: '获取定位成功',
          });
          that.setData({
            jindu: longitude,
            weidu: latitude,
          })
        } else {
          wx.showModal({
            title: '温馨提示',
            content: '请在微信设置开启允许定位',
            success: function (res) {
              if (res.confirm) { //这里是点击了确定以后
                console.log('用户点击确定')
    
              } else { //这里是点击了取消以后
                console.log('用户点击取消')
              }
            }
          })
        }
      }
    })
  },








  scrollFunc(){

    console.log(1);
    let totalP = this.data.totalPage //最大页码数
    const that = this
    let page = that.data.page + 1 // 当前页码+1，获取下一页的数据
    console.log('page', page);
    if (page <= totalP && totalP > 1) {
      that.setData({
        page: page,
      })
      console.log(that.data.page);
      wx.request({
        url: app.globalData.interface+'/squareDance/API_5253_unGetAddShanghuList',
        method: 'POST',
        data: {

          EMPLOYEE_ID: that.data.mealsList,
          OPEN_ID: that.data.openid, //用户OPEN_ID
          session_key: that.data.session_key,
          OPEN_UUID: that.data.jiami,
          currentPage: page,
          KeyWord: '',
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: res => {
          console.log('res', res);
          console.log('res', res.data.result);

          if (res.data.result == 'success') {
            that.setData({
              shangjiaxinaa: [...that.data.shangjiaxinaa, ...res.data.data], //es6中的在旧数据中加其他数据,
            })

            wx.hideLoading()
            console.log('最大页码数', this.data.totalPage);

          }
        },
        fail: (res => {
          wx.hideLoading()
        })
      })
      console.log("56565656", this.data.page);

    } else {
      wx.showToast({
        title: '没有更多数据了',
        icon: 'error',
        duration: 1500,
      })
    }


  },













  

  onLoad(options) {

    let that = this
    that.setData({
      openid: app.globalData.openid,
      jiami: app.globalData.jiami,
      OPEN_ID: app.globalData.openid,
      session_key: app.globalData.session_key,
      mealsList: app.globalData.mealsList,

    })

  },
  onShow() {

    var that = this

    if (that.data.jiami == '' || that.data.session_key == '') {

      wx.login({
        success: function (res) {
          console.log(res);
          if (res.code) { //wx.login获取code。
            console.log(res.code);
            //发起网络请求

            wx.request({
              url: app.globalData.interface+'/post/API_1062_appGetOpenid',
              // url: 'http://192.168.3.173:8081/post/API_1062_appGetOpenid',
              method: 'GET',
              //向后端发送的数据
              data: {
                code: res.code //将code发送到后台服务器。
              },
              header: {
                "Content-Type": "application/x-www-form-urlencoded" //POST方式是这个
              },
              success: res => {
                console.log(res);
                if (res.data.result != 'success') {
                  console.log(1);
                  // wx.showToast({
                  //   title: '请获取手机号',
                  //   duration: 1000
                  // })
                } else {
                  var openid = res.data.openid;
                  app.globalData.openid = openid;

                  console.log(res.data.openid);
                  that.setData({
                    openid: res.data.openid
                  })
                  // that.scanCod()

                  that.setData({
                    phone: app.globalData.phone,

                    jiami: app.globalData.jiami,
                    OPEN_ID: app.globalData.openid,
                    openid: app.globalData.openid,
                    session_key: app.globalData.session_key,
                  })
                  console.log(that.data.phone);
                  console.log(that.data.jiami);
                  console.log(that.data.openid);
                  console.log(that.data.session_key);
                }

              }
            })
          } else {
            console.log('获取用户登录态失败！' + res.errMsg)
          }
        }
      });
    } else {

      console.log('成功');
    }







  },


  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    



  },














})